<?php
namespace Lib\Source\Driver\Zend;
use Lib\Data,
    Lib\Source\DriverAbstract;
    
class Registry extends DriverAbstract{
    /**
     * @var Data
     */
    protected $_storage;
    
    /**
     * @var Zend_Registry
     */
    protected $_registry;
    
    public function init(){
        $this->_registry = \Zend_Registry::getInstance();
    }
    
    public function load($name, $default = null){
        if($this->_registry->offsetExists($name)){
            $this->getStorage()->setValue($name, isset($this->_registry->$name)?$this->_registry->get($name):$default);
            return true;
        } else{
            $this->getStorage()->setValue($name, $default);
            return false;
        }
    }
    
	/**
     *  @see Lib\Source.DriverAbstract::saveData()
     */
    public function saveData($data){
        $result = false;
        foreach ($data as $name=>$value){
            $this->_registry->offsetSet($name, $value);
            $result = true;
        }       
        return $result;
    }
}